package org.gthelper.database;

//import java.sql.Connection;
//import java.sql.DriverManager;

import javax.naming.InitialContext;
import javax.sql.DataSource;


public class DBHandler {
	
//	public static String gT_dburl="jdbc:mysql://localhost:3306/gt_db";
//	public static String username="root";
//	public static String password="admin";
	public static String db_name="GT_db";
	public static String db_driver="com.mysql.jdbc.Driver";
	
	static{
		try {
			Class.forName(db_driver);
			java.sql.DriverManager.registerDriver(new com.mysql.jdbc.Driver());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	/*
	 * tomcat数据库连接池获取连接
	 */
	public static java.sql.Connection getconnection()throws Exception
	{
		//获取连接池中的连接
				InitialContext initCtx = new InitialContext(); 
				DataSource ds = (DataSource)initCtx.lookup("java:comp/env/"+db_name);  
				java.sql.Connection conn = ds.getConnection(); //获取连接。 
				return conn;
	}
	 
	
	
//	
//	/*
//	 * 基本的通过JDBC获取连接
//	 */
//	
//	public static Connection getconnection()throws Exception
//	{
//		Connection con = DriverManager.getConnection(gT_dburl,username,password);
//		return con;
//	}
//	
	/*
	 * 转化日期时间格式的类
	 */
	static public String getform_datetime(String originString)
    {
    	String newdatetimeString = originString.substring(0, 4)+originString.substring(5,7)+originString.substring(8,10)+originString.substring(11,13)+originString.substring(14,16)+originString.substring(17,19);
    	return newdatetimeString;
    }
	
}
